package pure.engine.model 
{
	import pure.debug.Logger;
	import pure.engine.core.IFrameListener;
	import pure.engine.core.ns_despair;
	import pure.engine.core.ProcessManager;
	
	use namespace ns_despair;
	
	/**
	 * 渲染管理器
	 * [Author] - PURE
	 * 
	 */
final public class RenderManager
{
	
	
	/**
	 * 加入
	 * 
	 * [Param] - R  脏渲染器
	 */
	ns_despair static function addDirtyRenderer(R:Renderer):void
	{
		m_dirtyRendererList[m_dirtyRendererLength++] = R;
	}
	
	
	/**
	 * 移除
	 * 
	 * [Param] - R  脏渲染器
	 */
	ns_despair static function removeDirtyRenderer(R:Renderer):void
	{
		var index:int = m_dirtyRendererList.indexOf(R);
		
		m_dirtyRendererList[index] = m_dirtyRendererList[--m_dirtyRendererLength];
		m_dirtyRendererList.pop();
	}
	
	
	/**
	 * 清空
	 */
	ns_despair static function clear():void
	{
		m_dirtyRendererList.length = m_dirtyRendererLength = 0;
	}
	
	
	/**
	 * 更新
	 */
	ns_despair static function updateAllDirtyRenderers():void
	{
		// debug !!
		//Logger.reportMessage('RenderManager', '更新渲染器 × ' + m_dirtyRendererLength);
		
		var l:int = m_dirtyRendererLength;
		
		while (--l > -1)
		{
			m_dirtyRendererList[l].modify();
		}
		m_dirtyRendererList.length = m_dirtyRendererLength = 0
	}
	

	
	
	//======================
	// Member
	//======================
	
	
	ns_despair static var m_dirtyRendererList:Vector.<Renderer> = new Vector.<Renderer>();

	ns_despair static var m_dirtyRendererLength:int;

}

}